<?php

declare(strict_types=1);
/**
 * Created by PhpStorm.
 * User: yangfan
 * Date: 2019/11/4
 * Time: 1:19 PM
 */

namespace App\Entity;

use App\Models\CouponCode;

class CouponCodeEntity extends ABaseEntity
{
    public function __construct(CouponCode $model)
    {
        $this->model = $model;
    }

    /**
     * @return int
     */
    public function getId()
    {
        return $this->model->id;
    }

    /**
     * @return int
     */
    public function getCouponGroupId()
    {
        return $this->model->coupon_group_id;
    }

    /**
     * @return string
     */
    public function getName()
    {
        return $this->model->name;
    }

    /**
     * 优惠券的价值
     *
     * @return float
     */
    public function getValue()
    {
        return $this->model->value;
    }

    /**
     * 使用的城市id， 多个 ID 以 ',' 分隔
     *
     * @return string
     */
    public function getCityId()
    {
        return $this->model->city_id;
    }

    /**
     * 最小使用金额
     *
     * @return int
     */
    public function getMinAmount()
    {
        return $this->model->min_amount;
    }

    /**
     * @return string
     */
    public function getNotBefore()
    {
        return $this->model->not_before;
    }

    /**
     * @return string
     */
    public function getNotAfter()
    {
        return $this->model->not_after;
    }

    /**
     * 唯一标识码
     *
     * @return string
     */
    public function getCode()
    {
        return $this->model->code;
    }

    /**
     * 优惠券的类型
     *
     * @return string
     */
    public function getType()
    {
        return $this->model->type;
    }

    /**
     * @return string
     */
    public function getBtype()
    {
        return $this->model->btype;
    }

    /**
     * @return int
     */
    public function getEnabled()
    {
        return $this->model->enabled;
    }

    /**
     * @return string
     */
    public function getAreaname()
    {
        return $this->model->areaname;
    }

    /**
     * @return string
     */
    public function getBookNotBefore()
    {
        return $this->model->book_not_before;
    }

    /**
     * @return string
     */
    public function getBookNotAfter()
    {
        return $this->model->book_not_after;
    }

    /**
     * @return void
     */
    public function setUsed(int $state)
    {
        $this->model->used = $state;
    }

    /**
     * 是否已经过期
     * todo 放到别处
     *
     * @return bool
     */
    public function expired()
    {
        if ($this->getNotAfter() && ($this->getNotAfter() <= date('Y-m-d H:i:s'))) {
            return true;
        }

        return false;
    }

    /**
     * @return string
     */
    public function getProductSkuTitle()
    {
        return (string) $this->model->product_sku_title;
    }

    /**
     * @return string
     */
    public function getUnuseProductSkuTitle()
    {
        return (string) $this->model->unuse_product_sku_title;
    }

    public function getUseProductOldPrice(): int
    {
        return $this->model->use_product_old_price;
    }

    public function setUseProductOldPrice(int $useProductOldPrice): void
    {
        $this->model->use_product_old_price = $useProductOldPrice;
    }
}
